package cn.jinjimi.framework.pay;

import android.app.Activity;

import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import cn.jinjimi.app.BuildConfig;

/**
 * 第三方支付平台支付 微信支付
 */
public class WXPayTask extends AbstractPayTask {
    public static final int TYPE = 8;

    private IWXAPI api;

    public WXPayTask(Activity context) {
        super(context);
        //暂时不考虑复用
        api = WXAPIFactory.createWXAPI(context, BuildConfig.WX_APP_ID);
    }

    @Override
    public String getName() {
        return "微信支付";
    }

    @Override
    public String getCode() {
        return "wxpay";
    }

    @Override
    public void pay(PayOrder order) {
        Activity context = getContext();
        if (context != null) {
            if (order instanceof PayOrder.WXPayOrderExt) {
                PayOrder.WXPayOrderExt ext = (PayOrder.WXPayOrderExt) order;
                PayReq req = new PayReq();
                req.appId = BuildConfig.WX_APP_ID;
                req.partnerId = ext.partnerId;
                req.prepayId = ext.prepayId;
                req.packageValue = ext.packageValue;
                req.nonceStr = ext.nonceStr;
                req.timeStamp = ext.timeStamp;
                req.sign = ext.sign;
                api.sendReq(req);
            }
        }
    }

}
